package com.alcj.service.impl;

import com.alcj.common.constant.SysConstant;
import com.alcj.common.utils.CmnUtil;
import com.alcj.mapper.LawNousMapper;
import com.alcj.mapper.NewsMapper;
import com.alcj.mapper.SiteShowMapper;
import com.alcj.model.LawNous;
import com.alcj.model.News;
import com.alcj.model.SiteShow;
import com.alcj.service.LawNousService;
import com.alcj.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author :chenxh
 * @version :v1.0
 * @Package :com.alcj.service.impl
 * @Description :(法规常识数据处理)
 * @date :2017/9/5 11:23
 */
@Service
public class LawNousServiceImpl implements LawNousService {

    @Autowired
    NewsMapper newsMapper;

    @Autowired
    LawNousMapper lawNousMapper;

    @Autowired
    SiteShowMapper siteShowMapper;

    /**
     * @Author: chenxh
     * @Description:查询获取首页显示法规常识
     * @Date: 2017/9/7 16:29
     * @param: record
     */
    @Override
    public List<LawNous> getLawNousList(String lawNousType) throws Exception{

        // 返回结果
        return this.lawNousMapper.selectLawNousList(lawNousType);
    }

    /**
     * @Author: chenxh
     * @Description:查询获取首页显示站点展示数据
     * @Date: 2017/9/7 16:29
     * @param: record
     */
    @Override
    public List<SiteShow> getSiteShowList(String city) throws Exception{
        // 处理结果集
        ArrayList<SiteShow> resultList = this.siteShowMapper.selectSiteShowList(city);

        if(CmnUtil.isEmpty(resultList) || resultList.size() < 5){
            String  defaultImg = CmnUtil.GetPropertyValue("application.properties","web.default-site");
            int workIndex = 0;
            if(!CmnUtil.isEmpty(resultList) && resultList.size() > 0){
                workIndex = resultList.size();
            }
            for(int index = workIndex;index < 5;index++){
                SiteShow workSiteShow = new SiteShow();
                workSiteShow.setImage(defaultImg);
                resultList.add(workSiteShow);
            }
        }
        // 最终结果集
        List<SiteShow> resultShowList = resultList;
        // 返回结果
        return resultShowList;
    }

    /**
     * @Author: chenxh
     * @Description:查询获取首页显示新闻资讯
     * @Date: 2017/9/7 16:29
     * @param: record
     */
    @Override
    public LawNous getDetailInfo(int lawnousId) throws Exception{

        // 返回结果
        return this.lawNousMapper.selectByPrimaryKey(lawnousId);
    }

    /**
     * @Author: chenxh
     * @Description:分页查询获取新闻资讯
     * @Date: 2017/9/7 16:29
     * @param: record
     */
    @Override
    public int getPageLawsCount(LawNous record) throws Exception{
        // 返回结果
        return this.lawNousMapper.selectPageLawNousListCount(record);
    }

    /**
     * @Author: chenxh
     * @Description:分页查询获取新闻资讯
     * @Date: 2017/9/7 16:29
     * @param: record
     */
    @Override
    public List<LawNous> getPageLawInfo(LawNous record) throws Exception{
        // 返回结果
        return this.lawNousMapper.selectPageLawNousList(record);
    }
}
